<template>
	<view class="content">
		<div class="list">
			<!-- <u-input v-model="value" type="textarea" :border="border" height="200" placeholder="请输入反馈内容" :columns="4" /> -->
			<textarea  v-model="value" placeholder="请输入反馈内容"/>
			<!-- <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" :multiple="true"
				:maxCount="3" width="106rpx" height="106rpx" :deletable="true" :previewImage="true"  :custom-btn="true">
				<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
					<img src="../../static/img/pic.png" mode="" style="width: 106rpx;height: 106rpx;"></img>
				</view>

			</u-upload> -->
			<view class="upload-img">
				<u-upload :fileList="fileList1" :before-upload="beforeUpload" @on-success="icoSuccess" :header="headers"
					:action="action" @on-remove="delimgs" :multiple="true" :maxCount="3" width="106rpx" height="106rpx"
					:deletable="true" :previewImage="true" :custom-btn="true"
					:limitType="['jpg', 'png', 'jpeg', 'mp4']">
					<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
						<img src="../../static/img/pic.png" mode=""
							style="width: 106rpx;height: 106rpx;position: relative; top: 0rpx; "></img>
					</view>
				</u-upload>
			</view>
		</div>
		<div class="list1">
			<div class="text">联系方式(选填)</div>
			<u-input v-model="value1" type="text" placeholder="请输入您的手机号码" class="input" />
		</div>
		<img src="../../static/img/icon2.png" alt="" class="refund" @click="addFeedBack()">

	</view>

</template>

<script>
	export default {
		onShow() {
			this.headers = {
				// 'Content-Type': 'application/x-www-form-urlencoded;',
				"Authorization": uni.getStorageSync('token') || 1,
				'Clientid': uni.getStorageSync('clientID') || 1
			}
		},
		data() {
			return {
				value: '',
				borser: false,
				value1: '',
				// 上传图片
				fileList: [],
				limitType: ['jpg', 'png', 'jpeg'],
				action: this.$myApi.upload,
				headers: ''


			}
		},
		methods: {
			
			getCurrentFormattedTime() {  
			  // 获取当前时间  
			  const now = new Date();  
			  
			  // 格式化日期和时间  
			  const year = now.getFullYear();  
			  const month = String(now.getMonth() + 1).padStart(2, '0');  
			  const date = String(now.getDate()).padStart(2, '0');  
			  const hours = String(now.getHours()).padStart(2, '0');  
			  const minutes = String(now.getMinutes()).padStart(2, '0');  
			  const seconds = String(now.getSeconds()).padStart(2, '0');  
			  
			  // 拼接字符串形成格式化日期时间  
			  const formattedTime = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;  
			  
			  return formattedTime;  
			} ,
			isPhone(phone) {
				var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
				if (!myreg.test(phone)) {
					return false;
				} else {
					return true;
				}
			},
			// 提交反馈
			addFeedBack() {
				if(this.value1 && !this.isPhone(this.value1)) {
					uni.showToast({
						title: '手机号格式不正确！',
						duration: 2000,
						icon: 'none'
					});
					return false;
				}
				let data = {
					// "customerId": 99,
					// "orderId": 22,
					// "rating": 8,
					"userId": uni.getStorageSync('openId').userId,
					"comment": this.value,
					"images": this.fileList.toString() || '',
					"contactInformation": this.value1,
					"feedbackDate": this.getCurrentFormattedTime()
				}
				this.$httpFormData.post(
					this.$myApi.addFeedback,
					data, {
						header: {
							// 'Content-Type': 'application/x-www-form-urlencoded',
							"Authorization": uni.getStorageSync('token') || 1,
							Clientid: uni.getStorageSync('clientID') || 1
						}
					}
				).then(res => {
					// console.log('提交个人反馈后', res);
					if(res.data.code == 200) {
						uni.showToast({
							title: '反馈成功，即将返回个人中心',
							duration: 2000,
							icon: 'none'
						});
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/newMy/index'
							})
						}, 2000)
					} else {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						});
					}

				}).catch(err => {
					uni.showToast({
						title: err.msg,
						duration: 2000,
						icon: 'none'
					});
				})

			},

			// 上传图片的一些操作
			beforeUpload() {
			
			},
			icoSuccess(e) {
				console.log(e, 112223, '上传完图片？？？？')
				this.fileList.push(e.data.url)
				console.log("添加后--------", this.fileList);
			},
			delimgs(is) {
				console.log("删除--------", is);
			
				// arr.splice(ind,1);
				this.fileList.splice(is, 1)
				console.log("删除后--------", this.fileList);
			},
			
		}




	}
</script>
<style>
	page {
		background-color: #F6F9FF;
	}
</style>
<style lang="scss" scoped>
	.content {
		width: 100%;

		.list {
			width: 690rpx;
			height: 369rpx;
			background: #FFFFFF;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			opacity: 1;
			margin-left: 30rpx;
			margin-top: 20rpx;
			padding-left: 20rpx;

		}

		.list1 {
			width: 690rpx;
			// height: 145rpx;
			background: #FFFFFF;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			opacity: 1;
			margin-left: 30rpx;
			margin-top: 20rpx;
			padding-left: 30rpx;

			.text {
				padding-top: 20rpx;

			}
		}

		.refund {
			width: 576rpx;
			height: 82rpx;
			margin-top: 450rpx;
			margin-left: 87rpx;

			&:active {
				opacity: 0.7;
			}
		}

	}

	::v-deep {
		.u-list-item {
			// margin-top: 5rpx;

			margin: 0rpx !important;
			margin-right: 10rpx !important;
			position: relative !important;
			top: -7rpx !important;
		}
		
		textarea {
			width: 648rpx;
			height: 236rpx;
			padding-top: 16rpx;
		}
	}
</style>
<style>
	page {
		background-color: #eee;
	}
</style>